package servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author 石小俊
 * @date 2023年10月19日 14:47
 * 绘制添加员工的页面
 */
@WebServlet("/showAddEmp")
public class ShowAddEmpServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 返回响应信息的时候,可能存在乱码
        // 乱码是由HttpServletResponse导致的
        // 因此,在响应前需要设置响应数据的格式
        // 其数据格式由两部分组成:文本格式;charset=字符集
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        out.println(" <!DOCTYPE html> ");
        out.println(" <html lang=\"en\"> ");
        out.println(" <head> ");
        out.println("     <meta charset=\"UTF-8\"> ");
        out.println("     <title>添加员工</title> ");
        out.println(" </head> ");
        out.println(" <body> ");
        out.println(" <h1>添加员工</h1> ");
        out.println(" <a href=\"findAll\">返回员工列表</a> ");
        out.println(" <hr> ");
        // 表单提交时实现页面跳转,跳转的地址可以是Servlet
        // 此处支持绝对路径与相对路径
//        out.println(" <form action=\"addEmp\" method=\"post\"> ");
        out.println(" <form action=\"life2\" method=\"post\"> ");
        out.println("     姓名:<input type=\"text\" name=\"name\"><br> ");
        out.println("     工资:<input type=\"text\" name=\"salary\"><br> ");
        out.println("     性别: ");
        out.println("     <input type=\"radio\" name=\"gender\" value=\"man\">男 ");
        out.println("     <input type=\"radio\" name=\"gender\" value=\"woman\">女<br> ");
        out.println("     学历: ");
        out.println("     <select name=\"edu\"> ");
        out.println("         <option value=\"-1\">请选择</option> ");
        out.println("         <option value=\"1\">大专</option> ");
        out.println("         <option value=\"2\">本科</option> ");
        out.println("         <option value=\"3\">研究生</option> ");
        out.println("     </select><br> ");
        out.println("     兴趣: ");
        out.println("     <input type=\"checkbox\" name=\"hobbies\" value=\"eat\">吃饭 ");
        out.println("     <input type=\"checkbox\" name=\"hobbies\" value=\"sleep\">睡觉 ");
        out.println("     <input type=\"checkbox\" name=\"hobbies\" value=\"study\">学习<br> ");
        out.println("     <input type=\"submit\" value=\"添加\"> ");
        out.println(" </form> ");
        out.println(" </body> ");
        out.println(" </html> ");
    }
}
